/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { Project, TaskDetails } from '@ohos/hvigor';
import { IncrementalExecTask } from '@ohos/hvigor';

import { CommonConst } from '../../const/common-const.js';
import { ProjectTaskService } from '../service/project-task-service.js';

/**
 * openHarmony基础app task
 *
 * @since 2022/1/10
 */
export abstract class OhosAppTask extends IncrementalExecTask {
  protected project: Project;
  protected service: ProjectTaskService;

  protected constructor(project: Project, taskService: ProjectTaskService, taskDetails: TaskDetails) {
    super(project, taskDetails);
    this.project = this.node as Project;
    this.service = taskService;
    this.initTaskDepends();
    this.getWorkerPool().warmUp(CommonConst.WARM_UP_SCRIPT);
  }

  protected abstract initTaskDepends(): void;

  /**
   * 为每个target执行task的具体逻辑
   *
   */
  protected abstract doTaskAction(): void;

  registryAction = (): Function => {
    return this.doTaskAction;
  };
}
